<!-- 供应商 -->
<template>
    <div class="supply container-content">
        <div class="app-view-box">
            <el-row>
                <el-col :span="24">
                    <h1 class="panel-title">供应商</h1>
                </el-col>
            </el-row>
            <el-row justify="end" class="export-container">
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addCustomer"
                    >新增</el-button
                >
                <el-button
                    type="primary"
                    icon="el-icon-download"
                    size="mini"
                    @click="exporting"
                    >导出</el-button
                >
            </el-row>

            <el-table
                ref="customerTable"
                :data="tableData"
                stripe
                style="width: 100%"
                @selection-change="handleSelectionChange"
            >
                <el-table-column
                    type="selection"
                    width="55"
                    align="center"
                ></el-table-column>
                <el-table-column
                    type="index"
                    width="55"
                    label="序号"
                    align="center"
                ></el-table-column>
                <el-table-column prop="supplierCode" label="编码">
                    <template slot-scope="scope">
                        {{ scope.row.supplierCode || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="supplierName" label="名称">
                    <template slot-scope="scope">
                        {{ scope.row.supplierName || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="forShort" label="简称">
                    <template slot-scope="scope">
                        {{ scope.row.forShort || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="supplierGroup" label="供应商分组">
                    <template slot-scope="scope">
                        {{ scope.row.supplierGroup || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="supplierLevel" label="供应商等级">
                    <template slot-scope="scope">
                        {{ scope.row.supplierLevel || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="classification" label="供应商分类">
                    <template slot-scope="scope">
                        {{ scope.row.classification || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="examineId" label="审核人">
                    <template slot-scope="scope">
                        {{ scope.row.examineId || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="examineTime" label="审核日期">
                    <template slot-scope="scope">
                        {{ scope.row.examineTime || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="dataState" label="数据状态">
                    <template slot-scope="scope">
                        {{ scope.row.dataState || "--" }}
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="流程状态">
                    <!-- -1暂存，0审批中，2已完成 -->
                    <template slot-scope="scope">
                        <el-tag
                            type="warning"
                            v-if="scope.row.state === '0'"
                        ></el-tag>
                        <el-tag
                            type="info"
                            v-if="scope.row.state === '-1'"
                        ></el-tag>
                        <el-tag
                            type="success"
                            v-if="scope.row.state === '2'"
                        ></el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="disabledState" label="禁用状态">
                    <template slot-scope="scope">
                        {{ scope.row.disabledState || "--" }}
                    </template>
                </el-table-column>

                <el-table-column label="操作" width="120">
                    <template slot-scope="scope">
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="提交"
                            placement="bottom"
                        >
                            <el-button
                                :disabled="scope.row.state !== '-1'"
                                type="text"
                                icon="el-icon-s-promotion"
                                @click="handleSubmit(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="详情"
                            placement="bottom"
                        >
                            <el-button
                                type="text"
                                icon="el-icon-more"
                                @click="handleDetail(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="编辑"
                            placement="bottom"
                        >
                            <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleEdit(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="删除"
                            placement="bottom"
                        >
                            <el-button
                                type="text"
                                icon="el-icon-delete"
                                @click="handleDelete(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            class="table-pagination"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            :page-size="limit"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40, 50, 100]"
        >
        </el-pagination>
    </div>
</template>
<script>
import { getSupplyList, submitSupply } from "@/api/system/supply";
import { getmenuToModel } from "@/api/model";
export default {
    data() {
        return {
            tableData: [],
            searchValue: "",
            total: 0,
            limit: 10,
            page: 1,
            selectRows: [],
        };
    },
    methods: {
        handleSizeChange(val) {
            this.limit = val;
            this.getData();
        },
        handleCurrentChange() {
            this.page = val;
            this.getData();
        },
        // 获取供应商列表
        getData() {
            // let type = 3;
            let params = {
                limit: this.limit,
                page: this.page,
            };
            getSupplyList(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total * 1;
            });
        },

        //新增
        addCustomer() {
            this.$store.dispatch("workflow/getModel", {
                menuId: this.$route.meta.menuId,
                type: "launch",
                businessType: "41",
            });
        },
        //客户详情
        handleDetail(index, row) {
            // this.$router.push({
            //   path: "/CustomerManager/CustomerDetail",
            //   query: { id: row.id },
            // });
        },
        // 编辑客户
        handleEdit(index, row) {
            // this.$router.push({
            //   path: "/CustomerManager/EditCustomer",
            //   query: { id: row.id },
            // });
        },
        handleSubmit(index, row) {
            getmenuToModel(this.$route.meta.menuId).then((res) => {
                submitSupply({
                    id: row.id,
                    businessType: "41",
                    modelId: res.data.id,
                }).then((res) => {
                    this.$message.success("提交成功");
                    this.getData();
                });
            });
        },
        // 删除客户
        handleDelete(index, row) {
            this.$confirm("请确定要删除所选的记录吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    deleteSupply(row.id).then((res) => {
                        if (res.code === 200) {
                            this.tableData.splice(index, 1);
                            this.$message({
                                type: "success",
                                message: "删除成功!",
                            });
                            this.getData();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        // 导出按钮
        exporting() {
            console.log("exporting");
        },
        // 表格checkcbox事件
        handleSelectionChange(rows) {
            this.selectRows = rows;
        },
    },

    created() {
        this.getData();
    },
};
</script>
<style lang="scss" scoped>
// .visits {
//   padding: 15px;
// }
.pagination {
    margin-top: 10px;
}

.filter-container {
    margin-bottom: 15px;
}

.export-container {
    margin: 15px 0;
}

.panel-title {
    font-size: 18px;
    color: #37474f;
    font-weight: 500;
    text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

.divider {
    margin: 0;
}
</style>
